package com.adcc.automation.gui.base;

import javafx.animation.FadeTransition;
import javafx.animation.ParallelTransition;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.util.Duration;

public class TransitionFactory {
    
    public static ParallelTransition fadeOut(EventHandler<ActionEvent> event, Node... nodes){
        // 创建出一个 FadeTransition 用于单独设置淡入的节点
        ParallelTransition parallelTransition = new ParallelTransition();
        for(Node node : nodes){
            FadeTransition fadeOut = new FadeTransition(Duration.seconds(0.3), node);
            fadeOut.setFromValue(1);
            fadeOut.setToValue(0);
            parallelTransition.getChildren().add(fadeOut);
        }
        parallelTransition.setOnFinished(event);
        return parallelTransition;
    }
    
    public static ParallelTransition fadeIn(EventHandler<ActionEvent> event,Node... nodes){
        ParallelTransition parallelTransition = new ParallelTransition();
        for(Node node : nodes){
            node.setVisible(true); // 先将要淡入的节点设置为可见
            FadeTransition fadeIn = new FadeTransition(Duration.seconds(0.5), node);
            fadeIn.setFromValue(0);
            fadeIn.setToValue(1);
            parallelTransition.getChildren().add(fadeIn);
        }
        parallelTransition.setOnFinished(event);
       return parallelTransition;
    }
}
